#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "resizeui.h"

#include <QAudioDeviceInfo>
#include <QAudioInput>
#include <QAudioOutput>

#include <QDebug>
#include <QFile>
#include <QFileDialog>
#include <QResizeEvent>

struct WAVFILEHEADER
{
    // RIFF 头
    char RiffName[4];
    unsigned long nRiffLength;

    // 数据类型标识符
    char WavName[4];

    // 格式块中的块头
    char FmtName[4];
    unsigned long nFmtLength;

    // 格式块中的块数据
    unsigned short nAudioFormat;
    unsigned short nChannleNumber;
    unsigned long nSampleRate;
    unsigned long nBytesPerSecond;
    unsigned short nBytesPerSample;
    unsigned short nBitsPerSample;

    // 数据块中的块头
    char    DATANAME[4];
    unsigned long   nDataLength;
};


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    ResizeUI resizeUi;

    void savePCM2WAV(QString src , QString dst);

    void resizeEvent(QResizeEvent *event);

private slots:
    void on_pushButton_3_clicked();

    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    void finishedPlaying(QAudio::State state);

private:
    Ui::MainWindow *ui;

    QFile outputFile;
    QFile inputFile;
    QAudioInput *audioIn;
    QAudioOutput *outAudio;

    QString pcmname;
    QAudioFormat format;

    QList<QAudioDeviceInfo> inputDevs,outputDevs;

    bool isRecord=false;
    bool isPlay=false;
};

#endif // MAINWINDOW_H
